pg_query is error -> select datas.ken_cd, datas.ken_name , datas.shiku_cd , datas.shiku_name, datas.shiku_cd as cd, datas.shiku_name as nm, datas.object_count as cnt from (select town.ken_cd, town.ken_name, town.shiku_cd, town.shiku_name, town.p_sort, coalesce(obj1.object_count, 0, obj1.object_count) as object_count from v_town town inner join m_shop_town shek on shek.shiku_cd = town.shiku_cd and substr(shop_cd , 1 , 3) = '116' left outer join ( select shiku_cd, count(*) as object_count from d_object_data where substr(shop_cd , 1 , 3) = '116' and shubetu_cd in (' shubetucd ') and org_regist_cd is null and koukai_flag in (1,2,3,4) and ( ( rosen_cd1 in ('' $(this).find('data1').text() '') ) or( rosen_cd2 in ('' $(this).find('data1').text() '') ) or( rosen_cd3 in ('' $(this).find('data1').text() '') )) group by shiku_cd ) obj1 on town.shiku_cd = obj1.shiku_cd group by town.ken_cd, town.ken_name, town.shiku_cd, town.shiku_name, town.p_sort, obj1.object_count ) datas, (select shiku_cd, min(sort) as k_sort from m_shop_town where substr(shop_cd , 1 , 3) = '116' group by shiku_cd ) shiku_cds where datas.shiku_cd = shiku_cds.shiku_cd order by datas.p_sort desc,shiku_cds.k_sort,datas.shiku_cd